package com.nike.amoeba.bean.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.nike.amoeba.bean.db.StockEpcBean
import kotlinx.coroutines.flow.Flow

/**
 * @Author nike
 * @Date 2023/7/28 10:34
 * @Description
 */
@Dao
interface StockEpcDao {

    /**
     * 增加
     */
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun add(vararg bean: StockEpcBean)

    /**
     * 删除
     */
    @Delete
    suspend fun delete(bean: StockEpcBean)

    //删除数据库表全部数据
    @Query("delete from StockEpcBean")
    suspend fun deleteAll()

    //根据用户ID删除全部
    @Query("DELETE FROM StockEpcBean WHERE userId = :id AND companyId = :companyId")
    suspend fun deleteById(id: String, companyId: String)

    /**
     * 查询所有
     */
    @Query("SELECT * FROM StockEpcBean")
    fun findAll(): List<StockEpcBean>

    /**
     *  根据订单查询全部
     */
    @Query("SELECT * FROM StockEpcBean WHERE RoNo =:roNo AND code =:code")
    fun findAll(roNo: String, code: String?): List<StockEpcBean>

    @Query("SELECT * FROM StockEpcBean WHERE OrderNo =:orderId")
    fun findOrderIdAll(orderId: String?): List<StockEpcBean>

    /**
     *  唯一查询
     */
    @Query("SELECT * FROM StockEpcBean WHERE RoNo =:roNo AND epc =:epc AND code =:code")
    fun find(roNo: String, epc: String, code: String?): StockEpcBean


    /**
     * 更新
     */
    @Update
    suspend fun update(bean: StockEpcBean)

}